#ifndef F_CAEmuTMTCServerC_h
#define F_CAEmuTMTCServerC_h

// ***********************************************************************

// class EDROOMTopContext

// ***********************************************************************



class EDROOMTopContext {

protected:

enum EDROOMCAEmuTMTCServerSignal { EDROOMSignalTimeout, EDROOMSignalDestroy, SNextSensorSsiDataFrame, SDataFrame, SSignalFrame, EmuGSDoublePackList, STMTCPackList, STMDoublePackList, SFinalTCPackets, STCPackList };


	friend class CAEmuTMTCServer;

	CAEmuTMTCServer &EDROOMcomponent;

	CEDROOMMessage * &Msg;

	CEDROOMMessage * &MsgBack;

	//Ports

	CEDROOMInterface & StoreAndNextFrame;
	CEDROOMInterface & SgiTMTCServer2;
	CEDROOMInterface & SgiTMTCServer;

	enum edroomStateId{I, Ready};

	enum IdTrans{SendTMPacks, Init, ReceiveTCPacks, SendTCPackList, StoreFrame, ReceiveAck, ReceiveNextSignal, ReceiveNextSignal_SendAck, ReceiveNextSignal_SendData,  EDROOMMEMORIA };

	//Constantes



	//Variables

	CDDataBurst &VDataBurst;
	CDFrame &VDataFrame;
	CPackListHandler &VEmuGSFree;
	CPackListHandler &VEmuGSTC;
	CPackListHandler &VFreePackList;
	int &VMessageNumber;
	int &VMessageReceived;
	bool_t &VMoreData;
	int &VnumMensajeTC;
	int &VnumMensajeTM;
	PackPool &VPackListPool;
	CPackListHandler &VTCPackList;
	CPackListHandler &VTMPackList;


	//Pool

	class CEDROOMPOOLCDTMTCCommServer:public CEDROOMProtectedMemoryPool {
		public:
		CEDROOMPOOLCDTMTCCommServer(TEDROOMUInt32 elemCount,CDTMTCCommServer *pMem, TEDROOMBool *pMarks);
		CDTMTCCommServer	* AllocData();
	};
	CEDROOMPOOLCDTMTCCommServer	& CEDROOMPoolCDTmTcCommServer;
	class CEDROOMPOOLCDFrame:public CEDROOMProtectedMemoryPool {
		public:
		CEDROOMPOOLCDFrame(TEDROOMUInt32 elemCount,CDFrame *pMem, TEDROOMBool *pMarks);
		CDFrame	* AllocData();
	};
	CEDROOMPOOLCDFrame	& EDROOMPoolCDFrame;
	class CEDROOMPOOLCDSignal:public CEDROOMProtectedMemoryPool {
		public:
		CEDROOMPOOLCDSignal(TEDROOMUInt32 elemCount,CDSignal *pMem, TEDROOMBool *pMarks);
		CDSignal	* AllocData();
	};
	CEDROOMPOOLCDSignal	& EDROOMPoolCDSignal;


	// CONSTRUCTORES

	EDROOMTopContext (CAEmuTMTCServer &act, CDDataBurst & EDROOMpVarVDataBurst, CDFrame & EDROOMpVarVDataFrame, CPackListHandler & EDROOMpVarVEmuGSFree, CPackListHandler & EDROOMpVarVEmuGSTC, CPackListHandler & EDROOMpVarVFreePackList, int & EDROOMpVarVMessageNumber, int & EDROOMpVarVMessageReceived, bool_t & EDROOMpVarVMoreData, int & EDROOMpVarVnumMensajeTC, int & EDROOMpVarVnumMensajeTM, PackPool & EDROOMpVarVPackListPool, CPackListHandler & EDROOMpVarVTCPackList, CPackListHandler & EDROOMpVarVTMPackList, CEDROOMPOOLCDTMTCCommServer & EDROOMpPoolCDTMTCCommServer, CEDROOMPOOLCDFrame & EDROOMpPoolCDFrame, CEDROOMPOOLCDSignal & EDROOMpPoolCDSignal );

	EDROOMTopContext ( EDROOMTopContext &contex );

public:

	bool EDROOMSearchContextTrans(TEDROOMTransId &edroomCurrentTrans);

	void EDROOMNuevoMens () { EDROOMcomponent.EDROOMNewMsg(); }

	// Funciones Definidas por el usuario

	void	FCheckFiles();

	bool_t	FGetFrames(int32_t numFile,byte_t *pMessage);

	bool_t	FGetTCPackets(int32_t numeroFichero,byte_t *pMessage);

	bool_t	FGetTMPackets(int32_t numeroFichero,byte_t *pMessage);

	void	FInit();

	void	FInitFreePackPool();

	void	FInitTCFiles();

	void	FInitTMFiles();

	void	FIntToChar(int32_t num,byte_t * cConvert);

	void	FReady();

	void	FReceiveNextSignal();

	void	FSendAck();

	void	FSendInitEmuGS();

	void	FSendNextData();

	void	FSendTCPackList();

	void	FSendTMPackets();

	void	FStoreAck();

	void	FStoreFrame();

	void	FStoreTCFiles();

	void	FStoreTCFrame(byte_t * pMessage);

	void	FStoreTCPackets();

	bool_t	GMoreData();

	void	images_to_multi_tm_packets();

};

// ***********************************************************************

// class EDROOMTopState

// ***********************************************************************



class EDROOMTopState : public EDROOMTopContext {

protected:



	EDROOMTopContext::edroomStateId edroomCurrentState;

	EDROOMTopContext::edroomStateId edroomNextState;

	//Variables

	CDDataBurst VDataBurst;
	CDFrame VDataFrame;
	CPackListHandler VEmuGSFree;
	CPackListHandler VEmuGSTC;
	CPackListHandler VFreePackList;
	int VMessageNumber;
	int VMessageReceived;
	bool_t VMoreData;
	int VnumMensajeTC;
	int VnumMensajeTM;
	PackPool VPackListPool;
	CPackListHandler VTCPackList;
	CPackListHandler VTMPackList;


	//Pools

	CEDROOMPOOLCDTMTCCommServer	CEDROOMPoolCDTmTcCommServer;
	CEDROOMPOOLCDFrame	EDROOMPoolCDFrame;
	CEDROOMPOOLCDSignal	EDROOMPoolCDSignal;


public:

	// CONSTRUCTOR

	EDROOMTopState (CAEmuTMTCServer &act, CEDROOMMemory *pEDROOMMemory  );


	// EDROOMBehaviour**********************************************

	void EDROOMBehaviour();

	// Inicio**********************************************

	void EDROOMInicio();

	// ***********************************************************************

	// SubEstado Inicial 

	// ***********************************************************************



	TEDROOMTransId EDROOMIllegada();

	// ***********************************************************************

	// SubEstado Hoja Ready

	// ***********************************************************************



	TEDROOMTransId EDROOMReadyllegada();

};


#endif
